#include "game.h"

#include <string>
#include <iostream>
#include <fstream>
#include <rapidxml_print.hpp>
#include "config.h"

Game::Game () : tickList(&map), player(&tickList) {
}

Game::~Game () {
}

void Game::LoadConfig (const std::string & configFile) throw(Error) {
	std::ifstream inputXML(configFile.c_str());
	std::string line, text;
	while (getline(inputXML, line)) {
		text += line;
	}
	ConfigXMLText.assign(text.begin(), text.end());
	ConfigXMLText.push_back('\0');
	try {
		ConfigXML.parse<0> (&ConfigXMLText[0]);
	} catch (rapidxml::parse_error & err) {
		throw Error("Error parsing XML in Game::LoadConfig();");
	}

	player.LoadConfig(ConfigXML);
	objTable.Load(ConfigXML);
}

void Game::LoadMap (const std::string & mapFile) throw(Error) {
	map.Load(mapFile, objTable);
}

void Game::Draw (SDL_Surface * screen) {
	map.Draw(screen);
}

void Game::PrintConfigXML () {
	std::cout << ConfigXML << std::endl;
}

void Game::PrintInfo () {
}
